﻿using System.Collections.Generic;
using System.Reflection;
using Castle.Core.Interceptor;

namespace Trentacular.SharePoint.Deployment.Data.Proxy
{
    public abstract class BaseListLazyInitializer<T> : BaseLazyInitializer<IList<T>>
    {
        protected override object Invoke(IInvocation invocation)
        {
            MethodInfo method = invocation.Method;
            string methodName = method.Name;
            int paramCount = method.GetParameters().Length;

            if (paramCount == 0)
            {
                if (methodName == "Finalize")
                    return null;

                if (methodName == "get_LazyInitializer")
                    return this;
            }

            return InvokeImplementation;
        }
    }
}
